package com.coderush.admin.core.config;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@OpenAPIDefinition(
        info = @Info(
                title = "后台管理系统",
                version = "1.0.0",
                description = "API文档说明",
                contact = @Contact(
                        name = "技术支持",
                        email = "support@example.com",
                        url = "https://example.com"
                ),
                license = @License(
                        name = "Apache 2.0",
                        url = "https://www.apache.org/licenses/LICENSE-2.0.html"
                ),
                termsOfService = "https://example.com/terms",
                extensions = {
                        @Extension(properties = {
                                @ExtensionProperty(name = "x-internal", value = "false")
                        })
                }
        ),
        servers = {
                @Server(
                        url = "http://localhost:8080",
                        description = "开发环境"
                ),
                @Server(
                        url = "https://api.example.com",
                        description = "生产环境"
                )
        },
        security = {
                @SecurityRequirement(name = "BearerAuth")
        },
        tags = {
                @Tag(name = "用户管理", description = "用户相关操作"),
                @Tag(name = "权限管理", description = "权限相关操作")
        },
        externalDocs = @ExternalDocumentation(
                description = "更多文档",
                url = "https://example.com/docs"
        )
)
public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components())
                .info(new io.swagger.v3.oas.models.info.Info()
                        .title("API文档")
                        .version("1.0")
                        .description("Spring Boot 3 + SpringDoc OpenAPI")
                        .contact(new io.swagger.v3.oas.models.info.Contact()
                                .name("开发团队")
                                .email("dev@example.com"))
                );
    }
}